package sample;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

/**
 * @author
 * @date 2018/05/21/20:588/
 * @description javaAPI第三章
 */
/*
1)查看指定URL的HTML源文档内容？
提示：使用URL类和URLConnection类
 */
public class Test{
    public static void main(String[] args) {
        BufferedReader reader=null;
        try {
            URL url=new URL("http://hotels.ctrip.com/hotel/shanghai2#ctm_ref=hod_hp_sb_lst");
            URLConnection urlc=url.openConnection();
            reader=new BufferedReader(new InputStreamReader(urlc.getInputStream()));
            String reply=null;
            while ((reply=reader.readLine())!=null){
                System.out.println(reply);
            }
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
        catch (IOException e){
            e.printStackTrace();
        }
        finally {
            if (null!=reader){
                try {
                    reader.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
